<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="__STATIC__/layui/css/layui.css"  media="all">
    <script src="__STATIC__/index/js/jquery-3.2.1.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
</head>
<body>
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>系统公告发布</legend>
    </fieldset>
    <form class="layui-form" action="">
    	<div style="margin-bottom: 20px;">
    		<label class="layui-form-label">人员选择：</label>
    		<div class="layui-input-inline">
    			<select name="xuanzhe" id="xuanzhe">
    			<option value="请选择">请选择</option>
    			<option value="0">全部</option>
    			<option value="-1">推广人</option>
    			<option value="-2">放单人</option>
    		</select>
    		</div>
    	</div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-inline">
                <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input" id="title">
            </div>
        </div>

        <div style="margin-top: 20px;">
        	<label class="layui-form-label">详情内容:</label>
            <textarea class="layui-textarea" id="LAY_demo1" style="display: none;">  </textarea>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <span class="layui-btn site-demo-layedit" lay-submit="" lay-filter="demo1" id="demo" >立即提交</span>
            </div>
        </div>
    </form>
</body>
<script type="text/javascript">
    layui.use('layedit', function(){
        var layedit = layui.layedit
        ,$ = layui.jquery;

        layedit.set({
            uploadImage: {
                url: '{:url("admin/notice/upload")}' //接口url
                ,type: 'post' //默认post
            }
        });
        //构建一个默认的编辑器
        var index = layedit.build('LAY_demo1',{
        	height:1000
        });
        $('#demo').on('click',function(){
            var content = layedit.getContent(index);
            //alert(content);
            var title = $('#title').val();
            var xuanzhe = $('#xuanzhe').val();
            
             if(xuanzhe=='请选择'){
               layui.use('layer', function(){
			   var layer = layui.layer;
			   layer.alert('请选择发送人', {icon: 2});
				});              
		 		return false	
            }
            
            if(title==''){
               layui.use('layer', function(){
			   var layer = layui.layer;
			   layer.alert('标题不能为空', {icon: 2});
				});              
		 		return false	
            }
            if(content==''){
            	layui.use('layer', function(){
			   var layer = layui.layer;
			   layer.alert('内容不能为空', {icon: 2});
				});              
		 		return false	
            }
            $.ajax({
            	type:"post",
            	url:"{:url('admin/notice/release_add')}",
            	data:{title:title,content:content,uid:xuanzhe},
            	success:function(res){
            		if(res.code==1){
            			layui.use('layer', function(){
							  var layer = layui.layer;
							  layer.alert(res.msg, {icon: 1},function(){
							     location.reload(); 
						    });
							});
            		}else{
            			layui.use('layer', function(){
							  var layer = layui.layer;
							  layer.alert(res.msg, {icon: 2},function(){
							     location.reload(); 
						    });
							});
            		}
            	}
            });
        })
    });

</script>
</html>
